﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;

namespace Budget.DataAccess.Repository
{
	public class BudgetRepository<T> : IDisposable, IRepository<T> where T : class
	{
		private BudgetDataContext context;

		public BudgetRepository( BudgetDataContext ctxt )
		{
			context = ctxt;
		}

		#region IRepository<T> Members

		public IQueryable<T> Query()
		{
			return context.GetTable<T>();
		}

		public void Add( T entity )
		{
			context.GetTable<T>().InsertOnSubmit( entity );
		}

		public void Attach( T entity )
		{
			context.GetTable<T>().Attach( entity, true );
		}

		public void Remove( T entity )
		{
			context.GetTable<T>().DeleteOnSubmit( entity );
		}

		public void SubmitChanges()
		{
			context.SubmitChanges();
		}

		#endregion

		#region IDisposable Members

		public void Dispose()
		{
			context.Dispose();
		}

		#endregion
	}
}
